//提示
export function tishi(type, msg) {
    this.$notification[type]({
        message: msg,
    });
    // if (type == "success") {
    //     this.$message.success(msg);
    // } else {
    //     this.$message.warning(msg);
    // }
}

let qxQuit = true

export const common = {
    //10位字符串转日期
    sjcDate(sjc) {
        // console.log(sjc)
        var date = new Date(sjc * 1000)
        var y = date.getFullYear()
        var m = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : "0" + (date.getMonth() + 1)
        var d = date.getDate() > 9 ? date.getDate() : "0" + date.getDate()
        var h = date.getHours() > 9 ? date.getHours() : "0" + date.getHours()
        var f = date.getMinutes() > 9 ? date.getMinutes() : "0" + date.getMinutes()
        var s = date.getSeconds() > 9 ? date.getSeconds() : "0" + date.getSeconds()
        var time = y + '-' + m + '-' + d + ' ' + h + ':' + f + ':' + s
        return time
    },
    //中国标准时间转日期
    chinaDate(china) {
        var date = new Date(china)
        var y = date.getFullYear()
        var m = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : "0" + (date.getMonth() + 1)
        var d = date.getDate() > 9 ? date.getDate() : "0" + date.getDate()
        var h = date.getHours() > 9 ? date.getHours() : "0" + date.getHours()
        var f = date.getMinutes() > 9 ? date.getMinutes() : "0" + date.getMinutes()
        var s = date.getSeconds() > 9 ? date.getSeconds() : "0" + date.getSeconds()
        var time = y + '-' + m + '-' + d + ' ' + h + ':' + f + ':' + s
        return time
    },
    //年月日
    ymdDate(ymd) {
        var date = new Date(ymd)
        var y = date.getFullYear()
        var m = date.getMonth() + 1 > 9 ? date.getMonth() + 1 : "0" + (date.getMonth() + 1)
        var d = date.getDate() > 9 ? date.getDate() : "0" + date.getDate()
        var time = y + '/' + m + '/' + d
        return time
    },
    //日期转10位字符串
    dateSjc(date) {
        var sjc = new Date(date).getTime()
        return sjc
    },
    qx(text, arr) {
        if (localStorage.getItem('qxList')) {
            var list = localStorage.getItem('qxList')
            if (text != '') {
                if (JSON.stringify(list).indexOf(text) != -1) {
                    return true
                } else {
                    return false
                }
            } else {
                for (var i = 0; i < arr.length; i++) {
                    if (JSON.stringify(list).indexOf(arr[i]) != -1) {
                        return true
                    }
                }
                return false
            }
        } else {
            if (qxQuit) {
                alert('权限不存在,请重新登录！')
                window.location.href = "/xQsyaldw"
                qxQuit = false
            }
        }
    },
    slText(tel, num1, num2, num3) {
        const start = tel.slice(0, num1)
        const end = tel.slice(-num2)
        var xing = ''
        for (var i = 0; i < num3; i++) {
            xing += '*'
        }
        return `${start}${xing}${end}`
    },
    generateRandom(length) {
        var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        var result = '';
        for (var i = 0; i < length; i++) {
            var randomIndex = Math.floor(Math.random() * characters.length);
            result += characters.charAt(randomIndex);
        }
        return result;
    }
}